﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using proRFID_DiemDanh.Khoa;
using proRFID_DiemDanh.Chung;

namespace proRFID_DiemDanh.GiaoVien
{
    public partial class SuaGiaoVien : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                lbMaGV.Text = Request["ID"];
                if(string.IsNullOrEmpty(lbMaGV.Text.Trim()))
                    Response.Redirect("../GiaoVien/GiaoVien.aspx");
                Load_DDL_Khoa();
                HienThi();
            }
            
        }
        
        void HienThi()
        {
            DataTable dt = new DataTable();
            dt = mdGiaoVien.sp_GiaoVien_Select(Convert.ToInt16(Request["ID"]), Convert.ToInt32(lbMaGV.Text));
            txt_HoGV.Text = dt.Rows[0]["HOGV"].ToString();
            txt_TenGV.Text = dt.Rows[0]["TENGV"].ToString();
            ddl_Khoa.SelectedValue = dt.Rows[0]["MAKHOA"].ToString();
        }

        void Load_DDL_Khoa()
        {
            DataTable dt = new DataTable();
            dt = mdKhoa.sp_Khoa_Select(0);
            ddl_Khoa.DataSource = dt;
            ddl_Khoa.DataValueField = "MAKHOA";
            ddl_Khoa.DataTextField = "TENKHOA";
            ddl_Khoa.DataBind();
        }
        protected void Imgcmd_SuaGV_Click(object sender, ImageClickEventArgs e)
        {
            DataTable dt = new DataTable();
            dt = mdGiaoVien.sp_GiaoVien_Update(Convert.ToInt32(Request["ID"]), txt_HoGV.Text, txt_TenGV.Text, Convert.ToInt32(ddl_Khoa.SelectedValue));
            if (dt.Rows[0]["ErrCode"].ToString() == "0")
            {
                mdMain.OKBox(this, dt.Rows[0]["ErrMsg"].ToString(), "/GiaoVien/GiaoVien.aspx");
            }
            else
            {
                mdMain.OKCancelBox(this, dt.Rows[0]["ErrMsg"].ToString() + ". Bạn có muốn thử lại không?", "/GiaoVien/GiaoVien.aspx");
            }
        }
        
    }
}